package com.yanqu.road.logic.sort.yrank;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.rank.yrank.UserYRank;
import com.yanqu.road.utils.string.StringUtils;

import java.util.Comparator;
import java.util.Objects;

public class UserYRankSort implements Comparator<UserYRank> {

    @Override
    public int compare(UserYRank o1, UserYRank o2) {
        if (o1.getIdKey().equals(String.valueOf(eGamePlayerEventType.SeacraftPirateRiotScoreRank.getValue()))) {
            int compare = Integer.compare(Integer.valueOf(o2.getParam()), Integer.valueOf(o1.getParam()));
            if (0 == compare) {
                compare = o2.getValue().compareTo(o1.getValue());
            }
            if (0 == compare) {
                compare = Long.compare(o1.getUpdateTime(), o2.getUpdateTime());
            }
            return compare;
        }

        if (o1.getIdKey().equals(String.valueOf(eGamePlayerEventType.SuiTangUserZhanGongRank.getValue()))) {
            int result = o2.getValue().compareTo(o1.getValue());
            if (result != 0) {
                return result;
            }
            return Long.compare(o1.getUpdateTime(), o2.getUpdateTime());
        }

        if (o1.getIdKey().equals(String.valueOf(eGamePlayerEventType.TwinsPassDamageRank.getValue()))) {
            int result = o2.getValue().compareTo(o1.getValue());
            if (result != 0) {
                return result;
            }

            long param1 = 0;
            long param2 = 0;

            if (!StringUtils.isNullOrEmpty(o1.getParam())) {
                param1 = Long.valueOf(o1.getParam());
            }
            if (!StringUtils.isNullOrEmpty(o2.getParam())) {
                param2 = Long.valueOf(o2.getParam());
            }

            if (param1 != param2) {
                return Long.compare(param2, param1);
            }
            return Long.compare(o1.getUpdateTime(), o2.getUpdateTime());

        }



        if (!Objects.equals(o1.getValue(), o2.getValue())) {
            return o2.getValue().compareTo(o1.getValue());
        }
        return Long.compare(o1.getUpdateTime(), o2.getUpdateTime());
    }
}
